import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem=new int[10];
    }

    public void push(int val) {
        if(isFull()) {
            //扩容
            elem= Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize++]=val;
    }

    public boolean isFull() {
        return usedSize==elem.length;
    }

    public int pop() {
        if(empty()) {
            return -1;//这里更合适做法是抛出一个异常
        }
        int toPop=elem[usedSize-1];
        usedSize--;
        return toPop;
    }

    public boolean empty() {
        return usedSize==0;
    }

    public int peek() {
        if(empty()) {
            return -1;//这里更合适做法是抛出一个异常
        }
        int toPeek=elem[usedSize-1];
        return toPeek;
    }
}
